/**
 * 仓库管理相关API
 */
import type { InventoryApi } from '#/models/inventory/inventory';

import { requestClient } from '#/api/request';
import type { PageResponse } from '#/types/common';

// 重新导出PageResponse类型，供其他inventory模块使用
export type { PageResponse };

/**
 * 仓库列表查询参数接口
 */
export interface WarehouseQueryParams {
  page?: number;
  pageSize?: number;
  name?: string;
  code?: string;
  status?: string;
  [key: string]: any;
}

/**
 * 获取仓库列表
 * @param params - 查询参数，支持分页、过滤和排序
 * @returns 分页的仓库列表数据
 */
export const getWarehouseList = (
  params?: WarehouseQueryParams,
): Promise<PageResponse<InventoryApi.Warehouse>> => {
  return requestClient.get('/inventory/warehouse/', { params });
};

/**
 * 获取单个仓库详情
 * @param warehouseId - 仓库ID
 * @returns 仓库详情
 */
export const getWarehouse = (
  warehouseId: number,
): Promise<InventoryApi.Warehouse> =>
  requestClient.get(`/inventory/warehouse/${warehouseId}/`);

/**
 * 创建仓库
 * @param data - 仓库数据
 * @returns 创建成功的仓库信息
 */
export const createWarehouse = (
  data: Partial<InventoryApi.Warehouse>,
): Promise<InventoryApi.Warehouse> =>
  requestClient.post('/inventory/warehouse/', data);

/**
 * 更新仓库
 * @param warehouseId - 仓库ID
 * @param data - 更新的仓库信息
 * @returns 更新后的仓库信息
 */
export const updateWarehouse = (
  warehouseId: number,
  data: Partial<InventoryApi.Warehouse>,
): Promise<InventoryApi.Warehouse> =>
  requestClient.put(`/inventory/warehouse/${warehouseId}/`, data);

/**
 * 删除仓库
 * @param warehouseId - 仓库ID
 * @returns 删除结果
 */
export const deleteWarehouse = (warehouseId: number): Promise<any> => {
  return requestClient.delete(`/inventory/warehouse/${warehouseId}/`);
};
